var beautyImgObj = {
    el: '#pageApp',
    data: {
      currentIndex:null,
      currentAlbumId:null, 
      albumList:[],
    },
    components:{
    
    
    },
    methods: {
       getTinyAlbumModule:function(){
         var _this = this;
         g.ajax({
           type: 'GET',
           url: g.url.format('/api/author/getTinyAlbumModule'),
           success: function (result) { 
              _this.setAlbumList(result.data); 
           }
         });
       },
       setAlbumList:function(data){
        data.forEach(function(item,i){
          item.coverImg = g.url.imgFormat(item.albumImg);
          for(var j = 0 ; j < item.commendItems.length ; j++){
            item.commendItems[j].left = 10 + 22*j +'px';
          }
        })
        this.albumList = data;
        this.currentAlbumId = this.albumList[this.currentIndex].AlbumId;
        this.initSwiper();

       },
       initSwiper:function(){
        var _this = this;
        var lastIndex = _this.albumList.length -1;
        var swiperLength = $('.ykl-layout').width()*lastIndex;
        var photoSwiper = new Swiper('.swiper-container', {
            initialSlide:_this.currentIndex,
            observer:true,
            observeParents:true,
            onSliderMove:function(swiper){   
            },
            onTouchEnd:function(swiper){
              if(swiper.activeIndex == 0 && swiper.translate > 50){
                  g.modal.waiting({title:'已到第一张'});
              }
              if(swiper.activeIndex == lastIndex  && swiper.translate < -swiperLength){
                  g.modal.waiting({title:'已到最后一张'});
              }
              
            },
            onTransitionEnd: function(swiper){
                // _this.currentNum = swiper.activeIndex + 1; 
                _this.currentIndex = swiper.activeIndex;
                _this.currentAlbumId = _this.albumList[swiper.activeIndex].AlbumId;
                location.hash = _this.currentIndex;
            }
        }); 
      },
      toPhotoSwiper:function(id){
          console.log(id);
          g.window.openNew(g.url.urlHref('/page/photoSwiper.html?id='+ id));
      },
      toAddImg:function(){
         g.window.openNew(g.url.urlHref('/page/submitImg.html'));
      },
      toComment:function(){
          g.window.openNew(g.url.urlHref('/page/submitOption.html?id='+ this.currentAlbumId +'&type=3'));
      },
    },
    mounted:function () {
      this.getTinyAlbumModule();
      this.currentIndex = parseInt(location.hash.slice(1) || 0);
    }
};
var initPage = function(){
  new Vue(beautyImgObj);
};
